package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.manager.StaffManager;
import com.jiantong.user.service.StaffWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by niufei on 2017/4/21.
 *
 */
@Slf4j
@Service
@RpcProvider
public class StaffWriteServiceImpl implements StaffWriteService{

    private final StaffManager staffManager;

    @Autowired
    public StaffWriteServiceImpl(StaffManager staffManager) {
        this.staffManager = staffManager;
    }

//    @Override
//    public Response<Boolean> createGOVStaff(String userName, String mobile, List<Map<String , Object>> departments, List<Map<String , Object>> declareStations, List<Map<String , Object>> butcherFactories, Map<String , Object> roles) {
//        try {
//            return Response.ok(staffManager.createGovStaff(userName,mobile,departments,declareStations,butcherFactories,roles));
//        }catch (Exception e){
//            log.error("failed.to.create.staff userName = {},case = {}",userName, Throwables.getStackTraceAsString(e));
//            return Response.fail("failed.to.create.staff");
//        }
//    }
//
//    @Override
//    public Response<Boolean> updateGOVStaff(Long userId, String userName,List<Map<String , Object>> departments, List<Map<String , Object>> declareStations, List<Map<String , Object>> butcherFactories, Map<String , Object> roles) {
//        try {
//            return Response.ok(staffManager.updateGovStaff(userId,userName,departments,declareStations,butcherFactories,roles));
//        }catch (Exception e){
//            log.error("failed.to.update.staff userId = {},case = {}",userId, Throwables.getStackTraceAsString(e));
//            return Response.fail("failed.to.update.staff");
//        }
//    }

    @Override
    public Response<Boolean> createNGOStaff(String userName, String mobile, Integer appRole) {
        try {
            return Response.ok(staffManager.createNGOStaff(userName,mobile,appRole));
        }catch (Exception e){
            log.error("failed.to.create.staff userName = {},case = {}",userName, Throwables.getStackTraceAsString(e));
            return Response.fail("failed.to.create.staff");
        }
    }

    @Override
    public Response<Boolean> updateNGOStaff(Long userId, String userName,Integer appRole,Integer status) {
        try {
            return Response.ok(staffManager.updateNGOStaff(userId,userName,appRole,status));
        }catch (Exception e){
            log.error("failed.to.create.staff userId = {},case = {}",userId, Throwables.getStackTraceAsString(e));
            return Response.fail("failed.to.create.staff");
        }
    }
}
